package cc.abanlee.framework.security.config;

import cc.abanlee.framework.security.core.filter.TokenAuthenticationFilter;
import cc.abanlee.framework.security.core.handler.CustomAccessDeniedHandler;
import cc.abanlee.framework.security.core.handler.CustomAuthenticationEntryPoint;
import cc.abanlee.module.system.api.oauth2.OAuth2TokenApi;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.web.AuthenticationEntryPoint;
import org.springframework.security.web.access.AccessDeniedHandler;
import org.springframework.web.filter.OncePerRequestFilter;

/**
 * @author: create by
 * @version: v1.0
 * @description:
 * @date:2022/8/30
 */
@Configuration
public class LiSecurityAutoConfiguration {


    /**
     * 认证失败处理类 Bean
     */
    @Bean
    public AuthenticationEntryPoint authenticationEntryPoint() {
        return new CustomAuthenticationEntryPoint();
    }

    @Bean
    public OncePerRequestFilter oncePerRequestFilter(OAuth2TokenApi oauth2TokenApi){
        return new TokenAuthenticationFilter(oauth2TokenApi);
    }

    @Bean
    public AccessDeniedHandler accessDeniedHandler(){
        return new CustomAccessDeniedHandler();
    }
}
